package com.hsjk.szwj.module.pay.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hsjk.szwj.module.pay.dal.dataobject.system.MchAppDO;
import com.hsjk.szwj.module.pay.dal.dataobject.system.MchInfoDO;
import com.hsjk.szwj.module.pay.dal.mysql.IMchAppMapper;
import com.hsjk.szwj.module.pay.dal.mysql.IMchInfoMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author chenjiawei
 * @desc
 * @Date 2023/08/21 16:26
 **/
@Service
public class MchAppServiceImpl implements IMchAppService {
    @Resource
    private IMchAppMapper mchAppMapper;
    @Resource
    private IMchInfoMapper mchInfoMapper;

    @Override
    public List<MchAppDO> listByMchId(Long mchId) {
        return mchAppMapper.listByMchId(mchId);
    }

    @Override
    public MchAppDO getById(Long id) {
        return mchAppMapper.selectById(id);
    }

    @Override
    public MchAppDO getByTenant() {
        return mchAppMapper.selectOne(new LambdaQueryWrapper<>());
    }

    @Override
    public MchAppDO getByWayCode(String wayCode) {
        return null;
    }

    @Override
    public MchAppDO getByAppId(String appId) {
        return mchAppMapper.selectOne(new LambdaQueryWrapper<MchAppDO>()
                .eq(MchAppDO::getAppId, appId));
    }

    @Override
    public MchAppDO getInfo() {
        return mchAppMapper.selectOne(new LambdaQueryWrapper<>());
    }

    @Override
    public MchAppDO getOneByMchIdAndId(Long mchId, Long appId) {
        MchInfoDO mchInfoDO =
                mchInfoMapper.selectOne(new LambdaQueryWrapper<MchInfoDO>()
                        .eq(MchInfoDO::getId, mchId));
        return mchAppMapper.selectOne(new LambdaQueryWrapper<MchAppDO>()
                .eq(MchAppDO::getMchId, mchInfoDO.getId())
                .eq(MchAppDO::getId, appId));
    }

    @Override
    public List<MchAppDO> list(LambdaQueryWrapper<MchAppDO> queryWrapper) {
        return mchAppMapper.selectList(queryWrapper);
    }
}
